#!/usr/bin/env node
    
  // 启动静态文件服务器
  const KoaStatic = require('koa');
  const appStatic = new KoaStatic();
  const server = require('koa-static-cache');
  /* gzip压缩配置 end */
  
  // 1.主页静态网页 把静态页统一放到public中管理
  const publicServer = server('./views');
  // 2.重定向判断
  const redirect = ctx => {
    ctx.response.redirect('/pages/home.html')
  };
  appStatic.use(async (ctx, next) => {
    if (ctx.url === '/' ) {
      redirect(ctx)
    } else {
      await next()
    }
  });
  appStatic.use(publicServer);
  appStatic.listen(8000);
  console.log("服务已启动，请打开地址：http://localhost:8000/pages/home.html")